package com.wildworld.coreimpl;

import com.wildworld.core.IMap;
import com.wildworld.core.IWorld;
import com.wildworld.core.properties.MapProperty;
import com.wildworld.core.worldobjects.WorldObject;

/**
 * @author gzhebrakov
 *         Date: 18.08.12
 *         Time: 14:45
 */
public class IntelijWorldObject extends WorldObject {

    public boolean gender = true; // true is man

    public IntelijWorldObject(){
        setWidth(10d);
        setHeight(10d);
        setColor(255,100,100);
    }

    @Override
    public void doAction(IMap map, IWorld world){
        MapProperty property = map.getProperty();

        if (gender && checkMove(map, 6d, 6d)){
            move(6d, 6d);
        }else if (checkMove(map, -6d , -6d)) {
            move(-6d,-6d);
        }

    }

    public void setGender(boolean  gender){
        this.gender = gender;
        if (!gender){
            setColor(100,255,100);
        }
    }

    public boolean getGender(){
        return gender;
    }

    private boolean checkMove(IMap map, Double dx, Double dy){
        MapProperty p = map.getProperty();
        return (getX() + dx) > 0 && (getY() + dy) > 0 && ((getX()+getWidth() + dx) < p.getWidth()) && ((getY()+getHeight() + dy) < p.getHeight());
    }
}
